//
//  FXLabel.m
//  WangYiTest
//
//  Created by 袁飞霞 on 16/5/10.
//  Copyright © 2016年 cn.sophietobeabetterone. All rights reserved.
//

#import "FXLabel.h"

#define kLabelNormalFont 14
#define kLabelSelectedFont 18
@implementation FXLabel
-(void)setScale:(CGFloat)scale
{
//    _scale = scale;
//    
//    CGFloat currentFont =  (kLabelSelectedFont-kLabelNormalFont)*scale + kLabelNormalFont;
//    self.font = [UIFont systemFontOfSize:currentFont];
//    
//    self.textColor = [UIColor colorWithRed:scale green:0 blue:0 alpha:1];
//    
//     [self sizeToFit];
   
        _scale = scale;
        // 计算最大缩放比例
        CGFloat maxScale = (CGFloat)(kLabelSelectedFont - kLabelNormalFont) / kLabelNormalFont;
        // 计算实际缩放比例
        CGFloat currentScale = scale * maxScale + 1;
        
        self.transform = CGAffineTransformMakeScale(currentScale, currentScale);
        
        
        // 设置颜色
        self.textColor = [UIColor colorWithRed:scale green:0 blue:0 alpha:1.0];
        //    UILabel *label = [[UILabel alloc]init
        //                      ];
 

    
}
-(instancetype)initWithName:(NSString *)name
{
    if(self = [super init])
    {
        self.textColor = [UIColor blackColor];
        self.font = [UIFont systemFontOfSize:18];
        //先自适应大小 把label的宽度变宽
        self.text = name;
        [self sizeToFit];
        
      
        self.textAlignment = NSTextAlignmentCenter;
        //再更改font的大小 这样能保证label缩放到最大之后 label的宽度也是刚好够用的
        
        self.font = [UIFont systemFontOfSize:14];
        self.userInteractionEnabled = YES;
    
    }
    return self;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    if (self.labelSelected) {
        self.labelSelected();
    }

}

@end
